﻿using Emprise.Domain.Core.Bus;
using Emprise.Domain.Core.Data;
using Emprise.Domain.Core.Enums;
using Emprise.Domain.Core.Events;
using Emprise.Domain.Core.Models;
using Emprise.Domain.Core.Services;
using Emprise.Domain.Email.Entity;
using Microsoft.Extensions.Caching.Memory;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace Emprise.Domain.Email.Services
{
    public class EmailDomainService : BaseDomainService<EmailEntity>, IEmailDomainService
    {
        private readonly IRepository<EmailEntity> _emailRepository;
        private readonly IMemoryCache _cache;
        private readonly IMediatorHandler _bus;
        public EmailDomainService(IRepository<EmailEntity> emailRepository, IMemoryCache cache, IMediatorHandler bus) : base(emailRepository, cache, bus)
        {
            _emailRepository = emailRepository; 
            _cache = cache;
            _bus = bus;
        }


        public async Task<List<EmailEntity>> GetMyEmails(int playerId, int factionId)
        {
            //公告：系统发送给所有人
            //系统：系统发送给某个人
            //私信：个人发送给某个人
            //帮派：系统发送给某个帮派的所有人
            var query = await _emailRepository.GetAll(x => x.Type == EmailTypeEnum.公告 
            || ((x.Type == EmailTypeEnum.系统 || x.Type == EmailTypeEnum.私信) && x.TypeId == playerId) 
            || (factionId > 0 && x.Type == EmailTypeEnum.帮派 && x.TypeId == factionId));
            return query.ToList();
        }


    }
}
